﻿<%@ Page Title="AGR: Province Admin" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Provinces.aspx.cs" Inherits="AGR.Web.Pages.Administration.Provinces" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="RightContent" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <h3>Province Administration</h3>
    <hr />

    <asp:UpdatePanel ID="ProvinceUpdatePanel" runat="server">
    <ContentTemplate>

    <table>
        <tr>
            <td>
                <asp:Button ID="btnAdd" runat="server" Text="Add" CssClass="button" onclick="btnAdd_Click" />
                <asp:Button ID="btnDelete" runat="server" Text="Remove" CssClass="button" onclick="btnDelete_Click" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="ProvinceGridView" runat="server" CssClass="table-grid" AlternatingRowStyle-CssClass="odd" FooterStyle-CssClass="table-grid-footer"
                EmptyDataRowStyle-CssClass="empty" EmptyDataText="No countries found." PagerStyle-CssClass="pager"
                DataKeyNames="ProvinceName"
                AutoGenerateColumns="False" onrowcommand="ProvinceGridView_OnRowCommand"
                onrowcancelingedit="ProvinceGridView_RowCancelingEdit" onrowediting="ProvinceGridView_RowEditing" onrowupdating="ProvinceGridView_RowUpdating" 
                onpageindexchanging="ProvinceGridView_PageIndexChanging"
                AllowPaging="True" PageSize="10">
                    <PagerSettings Mode="NumericFirstLast" Position="Bottom"/>
                    <Columns>
                        <asp:TemplateField HeaderText="Select" HeaderStyle-Width="40px" 
                         HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelect" runat="server" CausesValidation="False"> </asp:CheckBox>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:CheckBox ID="chkSelect" runat="server" Enabled="false" CausesValidation="False"> </asp:CheckBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                    <strong>Add</strong>
                                </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Options" HeaderStyle-Width="90px" HeaderStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkProvinceEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton ID="lnkProvinceCancel" runat="server" CausesValidation="False"  CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                &nbsp;
                                <asp:LinkButton ID="lnkProvinceUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"
                                    ValidationGroup="ProvinceUpdateValidationGroup"></asp:LinkButton>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:LinkButton ID="btnProvinceCancel" runat="server" Text="Cancel" CausesValidation="false" UseSubmitBehavior="false" CommandName="CancelInsert" />
                                &nbsp;
                                <asp:LinkButton ID="btnProvinceInsert" runat="server" Text="Save" UseSubmitBehavior="false" CommandName="Insert"
                                    ValidationGroup="ProvinceSaveValidationGroup" />
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Country ID" HeaderStyle-Width="60px">
                            <ItemTemplate><%# Eval("CountryId")%></ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="lblCountryId" runat="server"></asp:Label>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:Label ID="lblCountryId" runat="server"></asp:Label>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Country" HeaderStyle-Width="110px">
                            <ItemTemplate><%# Eval("CountryName")%></ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlCountryName" runat="server" OnSelectedIndexChanged="CountryNameEdit_OnSelectedIndexChanged" AutoPostBack="true" />
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="ddlCountryName" runat="server" OnSelectedIndexChanged="CountryNameAdd_OnSelectedIndexChanged" AutoPostBack="true" />
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Code" HeaderStyle-Width="35px">
                            <ItemTemplate><%# Eval("ProvinceCode")%></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtProvinceCode" runat="server" Text='<%# Eval("ProvinceCode")%>' MaxLength="2" Width="20px"></asp:TextBox>
                                <asp:RequiredFieldValidator ControlToValidate="txtProvinceCode" ID="ProvinceCodeValidator" runat="server" ErrorMessage=" * "
                                    Display="Dynamic" CssClass="ClassValidator" ValidationGroup="ProvinceUpdateValidationGroup" ></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtProvinceCode" runat="server" Width="20px" MaxLength="2"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="ProvinceCodeValidator" runat="server" ErrorMessage=" * " Display="Dynamic" CssClass="ClassValidator"
                                    ControlToValidate="txtProvinceCode" ValidationGroup="ProvinceSaveValidationGroup"></asp:RequiredFieldValidator>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Province" HeaderStyle-Width="110px">
                            <ItemTemplate><%# Eval("ProvinceName")%></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtProvinceName" runat="server" Text='<%# Eval("ProvinceName")%>' Width="100px" Enabled="false"></asp:TextBox>
                                <asp:RequiredFieldValidator ControlToValidate="txtProvinceName" ID="ProvinceNameValidator" runat="server" ErrorMessage=" * " 
                                    Display="Dynamic" CssClass="ClassValidator" ValidationGroup="ProvinceUpdateValidationGroup" ></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtProvinceName" runat="server" Width="100px"></asp:TextBox>
                                <asp:RequiredFieldValidator ControlToValidate="txtProvinceName" ID="ProvinceNameValidator" runat="server" ErrorMessage=" * " 
                                    Display="Dynamic" CssClass="ClassValidator"  ValidationGroup="ProvinceSaveValidationGroup" ></asp:RequiredFieldValidator>
                            </FooterTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Displayed" HeaderStyle-Width="50px" FooterStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:CheckBox ID="chkDisplayed" runat="server" Enabled="false" 
                                    Checked='<%# (Convert.ToInt32(Eval("Displayed")) == 1) ? true : false%>' CausesValidation="False"></asp:CheckBox>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:CheckBox ID="chkDisplayed" runat="server" Enabled="true"
                                    Checked='<%# (Convert.ToInt32(Eval("Displayed")) == 1) ? true : false%>' CausesValidation="False"></asp:CheckBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:CheckBox ID="chkDisplayed" runat="server" CausesValidation="False" />
                            </FooterTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                            <FooterStyle HorizontalAlign="Center" />
                        </asp:TemplateField>

                        <asp:BoundField DataField="DateCreated" HeaderText="Date Created" HeaderStyle-Width="120px" ReadOnly="true"/>
                        <asp:BoundField DataField="UserCreated" HeaderText="User Created" HeaderStyle-Width="85px" ReadOnly="true" />
                        <asp:BoundField DataField="DateModified" HeaderText="Date Modified" HeaderStyle-Width="120px" ReadOnly="true"/>
                        <asp:BoundField DataField="UserModified" HeaderText="User Modified" HeaderStyle-Width="85px" ReadOnly="true" />
                    </Columns>
                    <PagerStyle HorizontalAlign="Right" Wrap="False" />
                </asp:GridView>
            </td>
        </tr>
    </table>

    </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdateProgress ID="ProvinceUpdateProgress" runat="server" AssociatedUpdatePanelID="ProvinceUpdatePanel">
    <ProgressTemplate>
        <div class="modalpopup">
            <div class="loadingpopup">
                <div class="center">
                    <img src="<%=ResolveUrl("~/Content/Images/Shared/spinner.gif") %>" alt="" height="50" width="50" />
                </div>
                <div class="center">
                     Please wait...
                </div>
            </div>
        </div>
    </ProgressTemplate>
    </asp:UpdateProgress>
</asp:Content>
